Skip to content

perf(stake): cache + multicall the orbit graph; fix stale dialog copy - #196

Merged
sktbrd merged 1 commit into
mainfrom
perf/orbit-cached-multicall
Jul 25, 2026
Merged

perf(stake): cache + multicall the orbit graph; fix stale dialog copy#196
sktbrd merged 1 commit into
mainfrom
perf/orbit-cached-multicall

Conversation

@sktbrd

@sktbrd sktbrd commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Why the orbit was slow

useStakeGraph did the whole thing client-side on every mount: per rider vault it fetched backers, then in a sequential loop read balanceOf + convertToAssets for each backer (2 RPC round-trips each), plus per-pool MOR log scans and per-user usersData reads. Dozens of serial round-trips → slow paint.

Smart tricks

  • Server-side + cached: new GET /api/stake-graph (revalidate 60s + stale-while-revalidate 300s). The graph is user-independent, so it's shared across all users — warm loads are instant JSON.
  • Multicall3: each vault's totalAssets / totalSupply / every balanceOf goes in one aggregated call; shares→assets is computed locally (shares * totalAssets / totalSupply), which deletes all per-backer convertToAssets calls. The MOR log scan (chunks) and usersData reads are parallelized and multicalled.
  • react-query client hook keeps it warm between navigations. Same public API + types (useStakeGraph(nonce)StakeGraph | null).

Net: cold compute collapses from ~2·N + scan round-trips to a handful; repeat/other-user loads hit cache.

Also: fixed wrong dialog copy

  • Disclaimer no longer claims staking "isn't wired to a contract yet" (it is now).
  • Intro no longer says "Stake ETH" (it's the opportunities model now).
  • Localized en + pt-br.

Multicall verified against a live vault (totalAssets/totalSupply/balance in one call). tsc + next build clean.

🤖 Generated with Claude Code

The orbit did dozens of sequential client RPC round-trips on every mount
(per-backer balanceOf + convertToAssets in a loop, per-pool log scans),
so it painted slowly. Move it server-side and cache it:

- New /api/stake-graph (revalidate 60s + stale-while-revalidate 300s), backed
  by src/services/stake-graph.ts. Shared across users → warm loads are instant.
- Multicall3: each vault's totalAssets/totalSupply/every balance goes in ONE
  aggregated call; shares→assets is computed locally, dropping all per-backer
  convertToAssets calls. MOR log scans + usersData reads are parallelized and
  multicalled too.
- useStakeGraph is now a thin react-query hook over the cached route (kept warm
  between navigations); same public API and types.

Also fixes wrong dialog copy: the disclaimer no longer claims staking "isn't
wired to a contract yet" (it is), and the intro no longer says "Stake ETH".
Localized en + pt-br.

Multicall verified against a live vault; tsc + next build clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 25, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated (UTC)
gnars-shadcn Ignored Ignored Jul 25, 2026 7:13pm
hackertestdao Ignored Ignored Jul 25, 2026 7:13pm

@sktbrd
sktbrd merged commit 9424864 into main Jul 25, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant